﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyFloridaHouse.LibDTO;
using Microsoft.SqlServer.Types;
using System.Data.SqlClient;
using System.Data;
using System.Data.Common;
using MyFloridaHouse.DataAccess.Extensions;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {
        /// <summary>
        /// GetDistrictGeographyShapesByLayer
        /// </summary>
        /// <param name="iUogIDList">The i uog ID list.</param>
        /// <returns>List of <see cref="SqlGeography"/></returns>
        /// <remarks>SPROC: usp_GetGeographiesFromUogIDList</remarks>
        public List<RegionShapeForReductionDTO> GetDistrictGeographyShapesByLayer(int ilayerID)
        {
            List<RegionShapeForReductionDTO> itemList = new List<RegionShapeForReductionDTO>();

            string storedProcedureName = "usp_tl10GetDistrictGeographyShapesByLayer10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("ilayerID", ilayerID);
                dataPartIDParm.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(RegionShapeForReductionDTODataContract.DataContract(rdr));
                    }
                }
            }

            return itemList;
        }

        public void UpdateDistrictGeographyShapesByLayer(List<RegionShapeForReductionDTO> geogList)
        {

            using (SqlConnection db = Connect())
            {
                
                SqlCommand nonQueryCommand = new SqlCommand("",db);
                foreach (RegionShapeForReductionDTO geog in geogList)
                {
                    nonQueryCommand.CommandText = "UPDATE tl10All10Geo SET mapObjectReduced='" + geog.mapGeog + "' WHERE regionID=" + geog.regionID;
                    nonQueryCommand.ExecuteNonQuery();
                }
            }
        }



        //public List<RegionShapeForReductionDTO> GetDistrictGeographyShapesByLayer(int ilayerID)
        //{
        //    List<RegionShapeForReductionDTO> itemList = new List<RegionShapeForReductionDTO>();

        //    Database db = DatabaseFactory.CreateDatabase("Reap");
        //    DbCommand dbCommand = db.GetStoredProcCommand("usp_tl10GetDistrictGeographyShapesByLayer10");
        //    db.AddInParameter(dbCommand, "ilayerID", DbType.Int32, ilayerID);
        //    using (SqlDataReader rdr = (SqlDataReader)db.ExecuteReader(dbCommand))
        //    {
        //        while (rdr.Read())
        //        {
        //            itemList.Add(RegionShapeForReductionDTODataContract.DataContract(rdr));
        //        }
        //    }
        //    return itemList;
        //}

        //public void UpdateDistrictGeographyShapesByLayer(List<RegionShapeForReductionDTO> geogList)
        //{
        //    Database db = DatabaseFactory.CreateDatabase("Reap");
        //    foreach (RegionShapeForReductionDTO geog in geogList)
        //    {
        //        string sqlCommand = "UPDATE tl10All10Geo SET mapObjectReduced='" + geog.mapGeog + "' WHERE regionID=" + geog.regionID;
        //        DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand);
        //        DataSet _dataSet = db.ExecuteDataSet(dbCommand);
        //    }
        //}


    }
}
